import request from '/@/utils/request';
import other from '/@/utils/other';
import { AxiosResponse } from 'axios';
import { ISysAttendanceRecord, ISysAttendanceRecordView, ISysAttendanceRecordVm, IBatchChangeRequest, ISearchByPersonRequest } from '/@/views/hr/sysattendancerecord/api/interface';
import { IResult } from '/@/types/common';

interface ISysAttendanceRecordApi {

  search(data: object): Promise<AxiosResponse<ISysAttendanceRecordView[]>>;
  get(id: string | number): Promise<AxiosResponse<ISysAttendanceRecordVm>>;
  add(data: ISysAttendanceRecordVm): Promise<AxiosResponse<ISysAttendanceRecord>>;
  edit(data: ISysAttendanceRecordVm): Promise<AxiosResponse<ISysAttendanceRecord>>;
  batchEdit(data: object): Promise<AxiosResponse>;
  delete(ids: (string | number)[]): Promise<AxiosResponse<number>>;
  export(data: object): Promise<void>;
  exportById(ids: (string | number)[]): Promise<void>;
  import(data: object): Promise<AxiosResponse<number>>;
  approve(data: object, tag: string): Promise<AxiosResponse<any, any>>;
  getSchedulingByPerson(data?: Partial<ISearchByPersonRequest>): Promise<AxiosResponse<[]>>;

  /** 批量修改排班 */
  batchChange(data: IBatchChangeRequest): Promise<AxiosResponse>;

  /**
   * 替班人员查询
   * @param data 查询请求参数
   */
  searchByPerson(data: ISearchByPersonRequest): Promise<AxiosResponse<[]>>;

  /**
   * 获取班次关联ID
   * @param data 查询请求参数
   */
  getAttendanceShiftId(data: ISearchByPersonRequest): Promise<AxiosResponse<[]>>;

}

function SysAttendanceRecordApi(): ISysAttendanceRecordApi {
  return {

    async search(data: object): Promise<AxiosResponse<ISysAttendanceRecordView[]>> {
      return await request({
        url: '/api/SysAttendanceRecord/Search',
        method: 'post',
        data,
      });
    },
    async get(id: string | number): Promise<AxiosResponse<ISysAttendanceRecordVm>> {
      return await request({
        url: `/api/SysAttendanceRecord/${id}`,
        method: 'get',
      });
    },
    async add(data: ISysAttendanceRecordVm): Promise<AxiosResponse<ISysAttendanceRecord>> {
      return await request({
        url: '/api/SysAttendanceRecord/Add',
        method: 'post',
        data,
      });
    },
    async edit(data: ISysAttendanceRecordVm): Promise<AxiosResponse<ISysAttendanceRecord>> {
      return await request({
        url: '/api/SysAttendanceRecord/Edit',
        method: 'put',
        data,
      });
    },
    async batchEdit(data: object): Promise<AxiosResponse> {
      return await request({
        url: '/api/SysAttendanceRecord/batchEdit',
        method: 'post',
        data,
      });
    },
    async delete(ids: (string | number)[]): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysAttendanceRecord/BatchDelete',
        method: 'post',
        data: ids,
      });
    },
    async export(data: object): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysAttendanceRecord/ExportExcel',
        method: 'post',
        data,
      });
      other.downloadFile(response);
    },
    async exportById(ids: (string | number)[]): Promise<void> {
      const response = await request<any, Blob>({
        responseType: 'blob',
        url: '/api/SysAttendanceRecord/ExportExcelByIds',
        method: 'post',
        data: ids,
      });
      other.downloadFile(response);
    },
    async import(data: object): Promise<AxiosResponse<number>> {
      return await request({
        url: '/api/SysAttendanceRecord/Import',
        method: 'post',
        data,
      });
    },
    async approve(data: object, tag: string) {
      return request({
        url: '/api/SysAttendanceRecord/approve?tag=' + tag,
        method: 'post',
        data,
      });
    },
    async getSchedulingByPerson(data?: Partial<ISearchByPersonRequest>): Promise<AxiosResponse<[]>> {
      return await request({
        url: '/api/SysAttendanceRecord/SearchByPerson',
        method: 'post',
        data,
      });
    },

    /**
     * 批量修改排班
     * 对指定人员在指定日期范围内进行排班修改
     * @param data 批量修改请求参数
     */
    async batchChange(data: IBatchChangeRequest): Promise<AxiosResponse> {
      return await request({
        url: '/api/sysattendancerecord/batchchange',
        method: 'post',
        data,
      });
    },



    /**
     * 获取班次关联ID
     * @param data 查询请求参数
     */
    async getAttendanceShiftId(data: ISearchByPersonRequest): Promise<AxiosResponse<[]>> {
      return await request({
        url: '/api/SysAttendanceRecord/SearchByPerson',
        method: 'post',
        data,
      });
    },


    /**
     * 查询人员ID列表
     * @param data 查询请求参数
     */
    async searchByPerson(data: ISearchByPersonRequest): Promise<AxiosResponse<[]>> {
      return await request({
        url: '/api/SysPerson/Search',
        method: 'post',
        data,
      });
    },

  }
}

export { SysAttendanceRecordApi };
